package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目接口")
public class NursingProjectController {
    @Autowired
    NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation("条件分页查询")
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(String name, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize, Integer status) {
        PageResponse<NursingProjectVo> result = nursingProjectService.getByPage(name, pageNum, pageSize, status);
        return ResponseResult.success(result);
    }

    @PostMapping
    @ApiOperation("新增")
    public ResponseResult add(@RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.add(nursingProjectDto);
        return ResponseResult.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询")
    public ResponseResult getById(@PathVariable Long id) {
        NursingProjectVo nursingProjectVo = nursingProjectService.getById(id);
        return ResponseResult.success(nursingProjectVo);
    }

    @PutMapping
    @ApiOperation("修改")
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.update(nursingProjectDto);
        return ResponseResult.success();
    }
    @DeleteMapping("/{id}")
    @ApiOperation("删除")
    public ResponseResult delete(@PathVariable Long id){
        nursingProjectService.delete(id);
        return ResponseResult.success();
    }
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用")
    public ResponseResult updateStatus(@PathVariable Long id,@PathVariable Integer status){
        nursingProjectService.updateStatus(id,status);
        return ResponseResult.success();
    }
    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult queryAll(){
        List<NursingProjectVo> list=nursingProjectService.queryAll();
        return ResponseResult.success(list);
    }


}
